#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, m;
int np[N];
vector<int> primes;
void init(int n) {
  np[1] = 1;
  rep(i, 2, n) {
    if (!np[i]) primes.push_back(i);
    for (int j : primes) {
      ll k = 1ll * j * i;
      if (k > n) break;
      np[k] = 1;
      if (i % j == 0) break;
    }
  }
}
int a[N];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  init(1e5 + 5);
  int t;
  cin >> t;
  while (t--) {
    cin >> n;
    int x = (n + 2) / 3;
    int p = *lower_bound(primes.begin(), primes.end(), x);
    int i = 1;
    a[1] = p;
    int l = p - 1, r = p + 1;
    while (l >= 1 && r <= n) {
      a[++i] = l--, a[++i] = r++;
    }
    while (l >= 1) a[++i] = l--;
    while (r <= n) a[++i] = r++;
    rep(i, 1, n) cout << a[i] << ' ';
    cout << endl;
  }
  return 0;
}